# DRM EGL OpenGL ES 测试程序 Makefile

# 编译器和标志
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O2
DEBUG_CFLAGS = -Wall -Wextra -std=c99 -g -DDEBUG

# 包含路径
INCLUDES = -I/usr/include/drm -I/usr/x86_64-linux-gnu/include/drm/

# 库文件
LIBS = -ldrm -lgbm -lEGL -lGLESv2 -lm

# 目标文件
TARGET = drm-egl-test
SOURCE = drm-egl-test.c

# 默认目标
all: $(TARGET)

# 编译目标
$(TARGET): $(SOURCE)
	@echo "编译 $(TARGET)..."
	$(CC) $(CFLAGS) $(INCLUDES) -o $(TARGET) $(SOURCE) $(LIBS)
	@echo "编译完成！"

# 调试版本
debug: $(SOURCE)
	@echo "编译调试版本..."
	$(CC) $(DEBUG_CFLAGS) $(INCLUDES) -o $(TARGET)-debug $(SOURCE) $(LIBS)
	@echo "调试版本编译完成！"

# 运行程序
run: $(TARGET)
	@echo "运行程序（需要 root 权限）..."
	sudo ./$(TARGET)

# 安装依赖
install-deps:
	@echo "安装编译依赖..."
	sudo apt update
	sudo apt install -y build-essential libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev

# 检查依赖
check-deps:
	@echo "检查编译依赖..."
	@pkg-config --exists libdrm && echo "✓ libdrm 已安装" || echo "✗ libdrm 缺失"
	@pkg-config --exists gbm && echo "✓ gbm 已安装" || echo "✗ gbm 缺失"
	@pkg-config --exists egl && echo "✓ egl 已安装" || echo "✗ egl 缺失"
	@pkg-config --exists glesv2 && echo "✓ glesv2 已安装" || echo "✗ glesv2 缺失"

# 清理
clean:
	@echo "清理编译文件..."
	rm -f $(TARGET) $(TARGET)-debug
	@echo "清理完成！"

# 显示帮助
help:
	@echo "可用的 make 目标："
	@echo "  all          - 编译程序（默认）"
	@echo "  debug        - 编译调试版本"
	@echo "  run          - 编译并运行程序"
	@echo "  install-deps - 安装编译依赖"
	@echo "  check-deps   - 检查依赖是否安装"
	@echo "  clean        - 清理编译文件"
	@echo "  help         - 显示此帮助信息"

# 显示编译信息
info:
	@echo "编译配置信息："
	@echo "  编译器: $(CC)"
	@echo "  编译标志: $(CFLAGS)"
	@echo "  包含路径: $(INCLUDES)"
	@echo "  链接库: $(LIBS)"
	@echo "  源文件: $(SOURCE)"
	@echo "  目标文件: $(TARGET)"

.PHONY: all debug run install-deps check-deps clean help info
